package cn.wolfcode.qo;

import lombok.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Getter
@Setter
@AllArgsConstructor
@ToString
@NoArgsConstructor
public class PageResult<T> {

    private int currentPage;//页面传过来的
    private int pageSize;//页面传过来的
    private List<T> list;//数据库查询出来的
    private int totalCount;//数据库查询出来的
    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, List<T> list, int totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.totalCount = totalCount;// 其他事计算出来的
        if (totalCount <= pageSize) {
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ?
                this.currentPage + 1 : this.totalPage;
        this.prevPage = this.currentPage - 1 >= 1 ?
                this.currentPage - 1:1;
    }
}